(ns clj-8583.binary
  (:import java.nio.charset.Charset))


(defn hex-to-bytes
  [hex]
  (map #(Integer/parseInt % 16) (re-seq #"[0-9A-Fa-f]{2}" hex)))

(def iso-8859-1-charset (Charset/forName "ISO-8859-1"))

(defn bytes-to-hex
  [bytes]
  (apply str (map #(format "%02X" (byte %)) bytes)))

(defn bytes-to-ascii [bytes]
  (new String (byte-array bytes) iso-8859-1-charset))

(defn bytes-to-str [array-of-bytes]
  (new String array-of-bytes iso-8859-1-charset))
